home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1995 / MacHack 1995.toast / Presentations / Presentations ’91 / MPW Stand-Alone Libraries / USingleSegSA.incl.p < prev    next >
Text File  |  1991-02-10  |  3KB  |  90 lines

  1. {--------------------------------------------------------------------------------------------------}
  2.  
  3. {$S TInit}
  4.  
  5. PROCEDURE TSingleSegSA.ISingleSegSA(aFile: FileSpec;
  6.                                 mainType: ResType;
  7.                                 mainID: Integer;
  8.                                 mainName: StringHandle);
  9.         
  10.     BEGIN
  11.         IMultiSegSA(aFile, mainType, mainID, mainName, kDfltOtherSeg);
  12.     END;
  13.     
  14. {--------------------------------------------------------------------------------------------------}
  15.  
  16. {$S TRes}
  17.  
  18. PROCEDURE TSingleSegSA.CalcSegTableSize(theCount: Integer; hasCtorDtorJT: Boolean); OVERRIDE;
  19.  
  20.     VAR
  21.         tempSize:    LongInt;
  22.         
  23.     BEGIN            
  24.         tempSize := 8;    { single segment standalone has only one segment; so it's 4 + 4}
  25.         ShowNumericalProgress('Segment table size = ', tempSize);
  26.         fSegTabSize := tempSize;
  27.     END;
  28.  
  29. {--------------------------------------------------------------------------------------------------}
  30.  
  31. {$S TRes}
  32. { We're concerned with all CODE resources since they }
  33. { will be merged into the standalone code resources. The only }
  34. { exceptions being CODE 0 and the static Ctor and Dtor jump tables}
  35. { which hide in a special CODE resource. }
  36.  
  37. FUNCTION TSingleSegSA.WillBeMerged(theID: Integer; theName: Str255): Boolean; OVERRIDE;
  38.  
  39.     BEGIN
  40.         IF (theID <> 0)    AND (theName <> kCtorDtorSeg ) THEN    { We are only concerned with CODE 1 }
  41.             WillBeMerged := TRUE
  42.         ELSE
  43.             WillBeMerged := FALSE;
  44.     END;
  45.     
  46. {--------------------------------------------------------------------------------------------------}
  47.  
  48. {$S TRes}
  49.  
  50. PROCEDURE TSingleSegSA.MergeCodeSegments(saCode: Handle; VAR saPos: LongInt); OVERRIDE;
  51.  
  52.     VAR
  53.         theCode:    Handle;
  54.         theCount:    Integer;
  55.         theID:        Integer;
  56.         theType:    ResType;
  57.         theName:    Str255;
  58.         theSize:    LongInt;
  59.         i:            Integer;
  60.         
  61.     BEGIN
  62.         INHERITED MergeCodeSegments(saCode, saPos);
  63.         
  64.         theCount := Count1Resources('CODE');
  65.         IF (theCount <= 0) THEN Failure(resNotFound, 0);
  66.         
  67.         { Get the remaining CODE segments. However, watch out for special segments! }
  68.         FOR i := 1 TO theCount DO
  69.             BEGIN
  70.                 theCode := NIL;
  71.                 theCode := Get1IndResource('CODE', i);
  72.                 FailNilResource(theCode);
  73.                 theSize := SizeResource(theCode);
  74.                 GetResInfo(theCode, theID, theType, theName);
  75.                 
  76.                 { Watch out for the main jump table or the CtorDtor jump table }
  77.                 IF (theID <> 1) AND WillBeMerged(theID, theName) THEN
  78.                     BEGIN
  79.                         Merge1Segment(theID, theCode, theSize, saCode, saPos);
  80.                         NumToString(theID, theName);
  81.                         theName := concat('Code ', theName, ' ends at: ');
  82.                         ShowNumericalProgress(theName, saPos);
  83.                     END;
  84.  
  85.                 ReleaseResource(theCode);
  86.             END;
  87.     END;
  88.  
  89. {--------------------------------------------------------------------------------------------------}
  90.